home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93c.txt / 000021_icon-group-sender _Wed Jul 21 06:12:42 1993.msg < prev    next >
Internet Message Format  |  1994-02-02  |  3KB

  1. Received: by cheltenham.cs.arizona.edu; Wed, 21 Jul 1993 08:43:02 MST
  2. Message-Id: <9307211312.AA03386@orpheus.tuc.noao.edu>
  3. From: swampler@noao.edu (Steve Wampler)
  4. Date: Wed, 21 Jul 1993 06:12:42 MST
  5. In-Reply-To: Paul_Abrahams@MTS.cc.Wayne.edu's mail message of Jul 20,  9:35pm.
  6. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  7. To: icon-group@cs.arizona.edu
  8. Subject: Re: Mysteries of "every"
  9. Status: R
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11.  
  12. On Jul 20 at  9:35pm, Paul_Abrahams@MTS.cc.Wayne.edu writes:
  13. }  
  14. } Cary Coutant wrote the following in response to my query:
  15. } -----------------------------
  16. }  >    every retval :=  8 * retval + ord(!s) - ord("0")
  17. }  >
  18. }  > Now the output of the program is 3 (the last digit), not 83.
  19. }  >
  20. }  > Can anyone explain to me what's going on?
  21. }  
  22. }  Try reversing the operands of the "+" operation:
  23. }  
  24. }      every retval := ord(!s) - ord("0") + 8 * retval
  25. }  
  26. }  Your problem was that the every was resuming the expression
  27. }  from the last suspended generator, so "8 * retval" was never
  28. }  being reevaluated.
  29. }  
  30. }  In situations like this, it's sometimes useful to replace a
  31. }  built-in operator with your own procedure, so you can see
  32. }  what's going on by setting TRACE.  For example:
  33. }  
  34. }      every retval :=  add(8 * retval, ord(!s) - ord("0"))
  35. } -----------------------------------
  36. }  
  37. } This explanation satisfies the ultimate test: Cary's version works.
  38. }  
  39. } Yet I've looked again at pages 15-16 of the Icon book and I still don't
  40. } get it.  The explanation of resumption on p. 15 is in terms of failure,
  41. } and there's no failure in the expression of my example.  The description
  42. } of "every" on p. 16 says that "expr1 is first evaluated and then
  43. } repeatedly resumed to produce all its values."  I would have thought that
  44. } resuming an expression that doesn't fail would cause it to be
  45. } =completely= reevaluated.
  46. }  
  47. } Clearly the assignment, which is the outermost level of the expression,
  48. } is evaluated on each iteration.  In fact, I verified (by attaching a
  49. } "do") that with s="123", retval takes on successive values of 1,2,3.  Yet
  50. } the second retval is not being reevaluated.  So which parts of an
  51. } expression are reevaluated and which ones aren't?  Is there any way to
  52. } deduce what happens from the explanation in the Icon book?
  53. }  
  54. } I'd appreciate any help I can get on this.  I'd also suggest that you
  55. } post your comments to icon-group rather than sending them to me
  56. } personally.
  57. }  
  58.  
  59. Well, actually, there *is* a failure.  It's inherent in the semantics
  60. of every.  For all practical purposes,
  61.  
  62.     every expr
  63.  
  64. is equivalent to:
  65.  
  66.     (expr) & &fail
  67.  
  68. (It gets a little trickier to describe the behavior when a 'do clause'
  69. is present, of if there is a 'break' or 'next' in the expr....).
  70.  
  71. 'Resumption' is also always a LIFO operation on generators, whether you
  72. care to think of every as above or as a separately semantic concept.
  73. It is fundamentally different than 'reevaluation'.  If you were to
  74. try and develop a non-LIFO model for resumption, it gets *very* tricky
  75. to still guarantee the combinatorial effects of multiple generators.
  76. In particular, you cannot use a stack based evaluation model.
  77.  
  78. Note that you can experiment with other models for resumption with
  79. Co-expressions, if you want to see what problems arise!
  80. ~t
  81.  
  82. -- 
  83. Steve Wampler
  84. swampler@noao.edu
  85. Gemini Project (under AURA)
  86.